import CommonAction from "../../../../../actions/common";
import {COMMON} from "../../../../../unit/util";

export default class HeaderAction extends CommonAction {
    constructor(comp) {
        super();
        this.comp = comp;
        this.dispatchType = 'staffCom/getStaffStruInfo'; //查询数据用到
    }

    getPostData = () => {
        let {advObj} = this.comp.state;
        let pk_org = advObj.org && advObj.org.map(item => {
            return item.refpk
        }) 
        let pk_psncl = advObj.psncl && advObj.psncl.map(item => {
            return item.refpk
        })
        return {
            age: advObj.age, //年龄统计
            edu: advObj.edu, //学历统计
            jobrank: advObj.jobrank, //职等统计
            pk_org: pk_org || null, //advObj.org && advObj.org.refpk,//	组织	string	如果是从统计值穿透过来的,为统计值对应的pk_org,即部门主键
            pk_psncl: pk_psncl || null, //advObj.psncl && advObj.psncl.refpk || null,//	人员类别	string
        }
    };

    clear = () => {
        let {props} = this.comp;
        let page = props.staffCom.page;
        // 根据页面 默认 变动统计/入离职统计
        let flag = page === COMMON.pageAgeEdu;
        let advObj = {
            org: "", //组织
            psncl: "", //人员类别
            age: flag, //年龄
            edu: flag, //学历
            jobrank: !flag, //职等
        };
        this.updateState({advObj})
    };

    updateState = (obj) => {
        return new Promise(resolve => {
            this.comp.setState(obj, resolve);
        })
    }
}